﻿using System.Windows.Controls;
using Utils.Extensions;

namespace StockAnalyst2.Plugins.Visualization.Historical
{
	internal partial class DetailViewer : UserControl
	{
		#region Properties

		public new DetailViewerVM DataContext
		{
			get
			{
				return (DetailViewerVM)base.DataContext;
			}
			set
			{
				if (this.DataContext != value)
				{
					base.DataContext = value;
				}
			}
		}

		#endregion

		#region Public Methods

		public DetailViewer()
		{
			InitializeComponent();
		}

		#endregion

		#region Event Handler
		
		private void UserControl_LayoutUpdated(object sender, System.EventArgs e)
		{
			if (this.AccumulatedResultColumn.ActualWidth > 20)
			{
				this.OperationStartColumn.SetFixedWidth(this.AccumulatedResultColumn.ActualWidth * 0.9);
				this.OperationEndColumn.SetFixedWidth(this.AccumulatedResultColumn.ActualWidth * 0.9);
				this.DurationColumn.SetFixedWidth(this.AccumulatedResultColumn.ActualWidth * 0.5);
				this.BuyPriceColumn.SetFixedWidth(this.AccumulatedResultColumn.ActualWidth * 0.65);
				this.SellPriceColumn.SetFixedWidth(this.AccumulatedResultColumn.ActualWidth * 0.65);
				this.VolumeColumn.SetFixedWidth(this.AccumulatedResultColumn.ActualWidth * 0.5);
				this.FeeColumn.SetFixedWidth(this.AccumulatedResultColumn.ActualWidth * 0.5);
				this.GrossResultColumn.SetFixedWidth(this.AccumulatedResultColumn.ActualWidth * 0.8);
				this.ResultColumn.SetFixedWidth(this.AccumulatedResultColumn.ActualWidth * 0.6);
				this.ResultPercentageColumn.SetFixedWidth(this.AccumulatedResultColumn.ActualWidth * 0.6);
				this.AmountRequiredColumn.SetFixedWidth(this.AccumulatedResultColumn.ActualWidth * 1);
				this.TotalAmountRequiredColumn.Width = new DataGridLength(1, DataGridLengthUnitType.Star);

				this.LayoutUpdated -= this.UserControl_LayoutUpdated;
			}
		}

		#endregion
	}
}
